/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author martin
 */
public class Arbol_BinarioTest {

    public Arbol_BinarioTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of Generar_arbol method, of class Arbol_Binario.
     */
    @Test
    public void testGenerar_arbol() {
        System.out.println("Generar_arbol");
        String cadena = "";
        Arbol_Binario instance = new Arbol_Binario();
        
        String expResult="";
        String result="";

        //**********************************************************************
        cadena ="((a|b)(c))*";
        instance.Generar_arbol(cadena);
        expResult = "(((a|b).c)*)";
        result = instance.padre.Mostrar_Nodo();
        assertEquals(expResult, result);
        //**********************************************************************
         //**********************************************************************
        cadena ="a|b";
        instance.Generar_arbol(cadena);
        expResult = "(a|b)";
        result = instance.padre.Mostrar_Nodo();
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena ="(a|"+Main.epsilon+")*";
        instance.Generar_arbol(cadena);
        expResult = "((a|"+Main.epsilon+")*)";
        result = instance.padre.Mostrar_Nodo();
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena ="(a)*|cde|e";
        instance.Generar_arbol(cadena);
        expResult = "(((a*)|((c.d).e))|e)";
        result = instance.padre.Mostrar_Nodo();
        assertEquals(expResult, result);
        //**********************************************************************
 
    }

    /**
     * Test of Generar_arbol method, of class Arbol_Binario.
     */
    @Test
    public void testGenerar_lista_de_simbolos() {
        System.out.println("Generar_lista_de_simbolos");
        Arbol_Binario instance = new Arbol_Binario();

        instance.Operadores_Unarios.clear();//borrar los operadores unarios
        instance.Operadores_Binarios.clear();//borrar los operadores binarios

        instance.Operadores_Unarios.add('*');
        instance.Operadores_Binarios.add('|');
        instance.Operadores_Binarios.add(Main.concat);
        
        //**********************************************************************
        String cadena ="(a|b)*||12";
        String expResult = "["+Main.epsilon+", a, b, 1, 2]";
        instance.Generar_lista_de_simbolos(cadena);
        String result = instance.lista_simbolos.toString();
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena ="a*|.a|ba1a2";
        expResult = "["+Main.epsilon+", a, b, 1, 2]";
        instance.Generar_lista_de_simbolos(cadena);
        result = instance.lista_simbolos.toString();
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena ="ab12";
        expResult = "["+Main.epsilon+", a, b, 1, 2]";
        instance.Generar_lista_de_simbolos(cadena);
        result = instance.lista_simbolos.toString();
        assertEquals(expResult, result);
        //**********************************************************************
    }

    /**
     * Test of Infix_to_Prefix_txt method, of class Arbol_Binario.
     */
    @Test
    public void testInfix_to_Prefix_txt() {
        System.out.println("Infix_to_Prefix_txt");
        String infijo = "0123";
        Arbol_Binario instance = new Arbol_Binario();
        instance.Generar_arbol(infijo);
        
        //**********************************************************************
        infijo = "(3)*.(2|1)|0";
        String expResult = "|.*3|210";
        String result = instance.Infix_to_Prefix_txt(infijo);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        infijo = "(0|1)*.(0|1)|1.2*";
        expResult = "|.*|01|01.1*2";
        result = instance.Infix_to_Prefix_txt(infijo);
        assertEquals(expResult, result);
        //**********************************************************************

    }

    /**
     * Test of Jerarquia method, of class Arbol_Binario.
     */
    @Test
    public void testJerarquia() {
        System.out.println("Jerarquia");
        Arbol_Binario instance = new Arbol_Binario();
        instance.Definir_Operadores("ab");
        char elemento1 = ' ';
        char elemento2 = ' ';
        
        //**********************************************************************
        elemento1 = ')';
        elemento2 = '*';
        boolean expResult = true;
        boolean result = instance.Jerarquia(elemento1) > instance.Jerarquia(elemento2);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        elemento1 = '|';
        elemento2 = '*';
        expResult = true;
        result = instance.Jerarquia(elemento1) > instance.Jerarquia(elemento2);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        elemento1 = '|';
        elemento2 = '.';
        expResult = true;
        result = instance.Jerarquia(elemento1) > instance.Jerarquia(elemento2);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        elemento1 = '(';
        elemento2 = '*';
        expResult = false;
        result = instance.Jerarquia(elemento1) > instance.Jerarquia(elemento2);
        assertEquals(expResult, result);
        //**********************************************************************
    }

    /**
     * Test of Jerarquia method, of class Arbol_Binario.
     */
    @Test
    public void testAgregar_concatenaciones() {
        System.out.println("Agregar_concatenaciones");
        Arbol_Binario instance = new Arbol_Binario();

        instance.Definir_Operadores("abcdefghijk");
        instance.Generar_lista_de_simbolos("abcdefghijk");

        String cadena = "";
        String expResult = "";
        String result="";

        //**********************************************************************
        cadena = "ab";
        expResult = "a.b";
        result=instance.Agregar_concatenaciones(cadena);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena = "a*b|cd";
        expResult = "a*.b|c.d";
        result=instance.Agregar_concatenaciones(cadena);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena = "a*(ab)";
        expResult = "a*.(a.b)";
        result=instance.Agregar_concatenaciones(cadena);
        assertEquals(expResult, result);
        //**********************************************************************
        //**********************************************************************
        cadena = "a*b(ab)|c*d";
        expResult = "a*.b.(a.b)|c*.d";
        result=instance.Agregar_concatenaciones(cadena);
        assertEquals(expResult, result);
        //**********************************************************************
    }

}